home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_xemacs.idb / usr / freeware / lib / xemacs-20.4 / lisp / utils / hide-copyleft.el.z / hide-copyleft.el
Encoding:
Text File  |  1998-05-21  |  5.4 KB  |  153 lines

  1. ;;; hide-copyleft.el --- hide obnoxious copyright prologs
  2.  
  3. ;; Copyright (C) 1997 Sun Microsystems.
  4.  
  5. ;; This file is part of XEmacs.
  6.  
  7. ;; XEmacs is free software; you can redistribute it and/or modify it
  8. ;; under the terms of the GNU General Public License as published by
  9. ;; the Free Software Foundation; either version 2, or (at your option)
  10. ;; any later version.
  11.  
  12. ;; XEmacs is distributed in the hope that it will be useful, but
  13. ;; WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15. ;; General Public License for more details.
  16.  
  17. ;; You should have received a copy of the GNU General Public License
  18. ;; along with XEmacs; see the file COPYING.  If not, write to the Free
  19. ;; Software Foundation, Inc. 59 Temple Place - Suite 330, Boston, MA
  20. ;; 02111-1307, USA.
  21.  
  22. ;;; Commentary:
  23.  
  24. ;; Written by Jamie Zawinski <jwz@netscape.com>, 19-jan-91.
  25. ;; Minor fixes by Martin Buchholz, 14-may-97.
  26. ;; Last modified  14-may-97.
  27. ;;
  28. ;; I sometimes find it tiresome to have fifteen lines of copyright notice at
  29. ;; the beginning of each file.  Meta-< does not take you to the beginning of
  30. ;; the code, it takes you a windowfull or two away, which can be tedious on
  31. ;; slow terminal lines.
  32. ;;
  33. ;; I know what the copyright notice says; so this code makes all but the first
  34. ;; line of it be invisible, by using Emacs's selective-display feature.  The
  35. ;; text is still present and unmodified, but it is invisible.
  36. ;;
  37. ;; Elide the copyright notice with "Meta-X hide-copyleft-region".  Make it
  38. ;; visible again with "Control-U Meta-X hide-copyleft-region".  Or, if you're
  39. ;; sure you're not gonna get sued, you can do something like this in your
  40. ;; .emacs file:
  41. ;;
  42. ;;       (autoload 'hide-copyleft-region   "hide-copyleft" nil t)
  43. ;;       (autoload 'unhide-copyleft-region "hide-copyleft" nil t)
  44. ;;       (add-hook 'emacs-lisp-mode-hook 'hide-copyleft-region)
  45. ;;       (add-hook 'c-mode-hook 'hide-copyleft-region)
  46. ;;
  47. ;; This code (obviously) has quite specific knowledge of the wording of the 
  48. ;; various copyrights I've run across.  Let me know if you find one on which
  49. ;; it fails.
  50.  
  51. (defvar copylefts-to-hide
  52.   ;; There are some extra backslashes in these strings to prevent this code
  53.   ;; from matching the definition of this list as the copyright notice!
  54.   '(;; GNU
  55.     ("free software\; you can redistribute it" .
  56.      "notice must be\ preserved on all")
  57.     ("free software\; you can redistribute it" .
  58.      "copy of the GNU General Public License.*\n?.*\n?.*\n?.*\n?.*\\(02139,\\|02111-1307\\)")
  59.     ("distributed in the hope that it will be useful\," .
  60.      "notice must be\ preserved on all")
  61.     ("free software\; you can redistribute it" .
  62.      "General Public License for more details\\.")
  63.     ;; X11
  64.     ("Permission to use\, copy, modify," .
  65.      "WITH THE USE OR PERFORMANCE")
  66.     ("Permission to use\, copy, modify," .
  67.      "without express or implied warranty")
  68.     ;; Motif
  69.     ("Copyright.*OPEN\ SOFTWARE FOUNDATION" .
  70.      "X Window System is a trademark of the")
  71.     ("THIS SOFTWARE\ IS FURNISHED UNDER A LICENSE" .
  72.      "X Window System is a trademark of the")
  73.     ;; UPenn
  74.     ("Permission to use\, copy, and distribute" .
  75.      " provided \"as is\" without")
  76.     ;; Evans & Sutherland, Solbourne.
  77.     ("Copyright 19[0-9][0-9] by " .
  78.      "OR PERFORMANCE OF THIS SOFTWARE\\.")
  79.     ;; TI Explorer
  80.     ("RESTRICTED RIGHTS LEGEND" . "All rights reserved\\.\\(\n;;; ?$\\)?")
  81.     ("^%%BeginDocumentation" . "^%%EndDocumentation")
  82.     )
  83.   "An alist of pairs of regexps which delimit copyright notices to hide.
  84. The first one found is hidden, so order is significant.")
  85.  
  86.  
  87. ;;;###autoload
  88. (defun hide-copyleft-region (&optional arg)
  89.   "Make the legal drivel at the front of this file invisible.  Unhide it again
  90. with C-u \\[hide-copyleft-region]."
  91.   (interactive "P")
  92.   (if arg
  93.       (unhide-copyleft-region)
  94.     (save-excursion
  95.      (save-restriction
  96.       (if selective-display (error "selective-display is already on."))
  97.       (catch 'Abort
  98.     (let ((mod-p (buffer-modified-p))
  99.           (buffer-read-only nil)
  100.           (rest copylefts-to-hide)
  101.           pair start end)
  102.       (widen)
  103.       (goto-char (point-min))
  104.       (while (and rest (not pair))
  105.         (save-excursion
  106.           (and (re-search-forward (car (car rest)) nil t)
  107.            (setq start (point))
  108.            (re-search-forward (cdr (car rest)) nil t)
  109.            (setq end (point)
  110.              pair (car rest))))
  111.         (setq rest (cdr rest)))
  112.       (setq x pair)
  113.       (or pair
  114.           (if (interactive-p)
  115.           (error "Couldn't find a CopyLeft to hide.")
  116.         (throw 'Abort nil)))
  117.       (goto-char end)
  118.       (forward-line 1)
  119.       ;; If the last line of the notice closes a C comment, don't
  120.       ;; hide that line (to avoid confusion...)
  121.       (if (save-excursion (forward-char -3) (looking-at "\\*/"))
  122.           (forward-line -1))
  123.       (setq end (point))
  124.       (goto-char start)
  125.       (forward-line 1)
  126.       (while (< (point) end)
  127.         (delete-char -1)
  128.         (insert "\^M")
  129.         (forward-line 1))
  130.       (setq selective-display t)
  131.       (set-buffer-modified-p mod-p)))))))
  132.  
  133. ;;;###autoload
  134. (defun unhide-copyleft-region ()
  135.   "If the legal nonsense at the top of this file is elided, make it visible again."
  136.   (save-excursion
  137.     (save-restriction
  138.       (widen)
  139.       (goto-char (point-min))
  140.       (let ((mod-p (buffer-modified-p))
  141.         (buffer-read-only nil)
  142.         end)
  143.     (or (search-forward "\^M" nil t) (error "Nothing hidden here, dude."))
  144.     (end-of-line)
  145.     (setq end (point))
  146.     (beginning-of-line)
  147.     (while (search-forward "\^M" end t)
  148.       (delete-char -1)
  149.       (insert "\^J"))
  150.     (set-buffer-modified-p mod-p)
  151.     (setq selective-display nil)))))
  152.  
  153.